package com.atguigu.springcloud.config;

import com.rabbitmq.client.ConnectionFactory;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author xiaolong
 * @version 1.0
 * @description: 控制是否启动rabbitmq
 * @date 2021/10/15 17:28
 */
@Configuration
@ConditionalOnProperty(value = "burn.enable", havingValue = "true")
public class StartRabbitmqConfig {

    @Value("${burn.enable:false}")
    private boolean rabbitmqEnable;

    @Bean(name = "myRabbitListenerContainer")
    public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory() {
        SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
        //如果项目中没有
        if (!rabbitmqEnable) {
            //是否自动启动
            factory.setAutoStartup(false);
        }
        return factory;
    }
}
